/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.aurelius.testngexecutionlogger;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.aurelius.testngexecutionlogger.entity.SimpleEntity;

/**
 *
 * @author Lukasz
 */
public class JpaStarter {

    public static void main(String[] args) throws InterruptedException {

        EntityManagerFactory emf =
                Persistence.createEntityManagerFactory("org.aurelius_testng-execution-logger_jar_1.0-SNAPSHOTPU");
        EntityManager em = emf.createEntityManager(); // Retrieve an application managed entity manager

        em.getTransaction().begin();

        SimpleEntity simpleEntity1 = new SimpleEntity(1 , "cos");
        SimpleEntity simpleEntity2 = new SimpleEntity(2 , "cos innego");

        em.persist(simpleEntity1);
        em.persist(simpleEntity2);

        em.getTransaction().commit();
//        Query createQuery = em.createNativeQuery("Select count(*) from Cos");
//        Object singleResult = createQuery.getSingleResult();
//
//        System.out.println(singleResult);

        SimpleEntity find = em.find(SimpleEntity.class, 2);

        System.out.println(find);

        em.close();
        emf.close(); //close at application end

    }
}
